﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Master_CommonDictionaryUpdForm
 * 类型：       控制层
 * 功能说明：   数据字典维护更新页面
 * 作者：       王伟栋
 * 创建日期：   2007/08/21
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.System.Web.Control;
using Shpm.App.Master.Dao;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.System;
using Shpm.App.Commons.Utils;

public partial class App_Master_CommonDictionaryUpdForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            // 保存接收的参数
            ViewState["InpDictNo"] = Convert.ToString(Context.Items["InpDictNo"]);
            ViewState["InpCatalog"] = Convert.ToString(Context.Items["InpCatalog"]);
            ViewState["InpTitle"] = Convert.ToString(Context.Items["InpTitle"]);
            ViewState["InpContent"] = Convert.ToString(Context.Items["InpContent"]);

            ViewState["ParamDictNo"] = Convert.ToString(Context.Items["ParamDictNo"]);
            ViewState["ParamCatalog"] = Convert.ToString(Context.Items["ParamCatalog"]);
            ViewState["ParamTitle"] = Convert.ToString(Context.Items["ParamTitle"]);
            ViewState["ParamContent"] = Convert.ToString(Context.Items["ParamContent"]);
            ViewState["ParamCommand"] = Convert.ToString(Context.Items["ParamCommand"]);
            ViewState["ParamPageIndex"] = Context.Items["ParamPageIndex"];

            ViewState["DictNo"] = Convert.ToString(Context.Items["DictNo"]);
            ViewState["Catalog"] = Convert.ToString(Context.Items["Catalog"]);

            // 初始化编辑画面
            CommonDictionaryBean paramBean = new CommonDictionaryBean();
            paramBean.DictNo = Convert.ToString(ViewState["DictNo"]);
            paramBean.Catalog = Convert.ToString(ViewState["Catalog"]);

            CommonDictionaryDao dao = new CommonDictionaryDao();
            paramBean = dao.Load(paramBean);

            if (paramBean != null)
            {
                txtDictNo.Text = paramBean.DictNo;
                txtCatalog.Text = paramBean.Catalog;
                txtTitle.Text = paramBean.Title;
                txtContent.Text = paramBean.Content;
                txtOrderNo.Text = Convert.ToString(paramBean.OrderNo);
                chkDefault.Checked = (paramBean.Default != null && paramBean.Default.Value);
            }
        }
    }

    protected void btnExit_Click(object sender, EventArgs e)
    {
        // 回传接收的参数
        Context.Items["InpDictNo"] = ViewState["InpDictNo"];
        Context.Items["InpCatalog"] = ViewState["InpCatalog"];
        Context.Items["InpTitle"] = ViewState["InpTitle"];
        Context.Items["InpContent"] = ViewState["InpContent"];

        Context.Items["ParamDictNo"] = ViewState["ParamDictNo"];
        Context.Items["ParamCatalog"] = ViewState["ParamCatalog"];
        Context.Items["ParamTitle"] = ViewState["ParamTitle"];
        Context.Items["ParamContent"] = ViewState["ParamContent"];
        Context.Items["ParamCommand"] = ViewState["ParamCommand"];
        Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];

        // 页面跳转到检索页面
        // Server.Transfer("~/App/Master/CommonDictionarySrhForm.aspx", true);
        ControllerUtils.Transfer(this.Context, "~/App/Master/CommonDictionarySrhForm.aspx", true);
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        CommonDictionaryBean paramBean = new CommonDictionaryBean();
        paramBean.DictNo = txtDictNo.Text;
        paramBean.Catalog = txtCatalog.Text;
        paramBean.Title = txtTitle.Text;
        paramBean.Content = txtContent.Text;
        paramBean.Default = chkDefault.Checked;
        paramBean.OrderNo = null;
        paramBean.UserId = "wwd";

        CommonDictionaryDao dao = new CommonDictionaryDao();

        CheckDataExistsAttribute chkDataExtAttr = new CheckDataExistsAttribute(
            dao, CommonDictionaryDao.EXISTS_COMMON_DICTIONARY, paramBean);
        chkDataExtAttr.Code = "E0203";
        ComAbsParamsAttribute param = new ComAbsParamsAttribute();
        param.Parameter = "字典编号";
        chkDataExtAttr.Parameters.Add(param);

        ComValidator1.CheckItems.Add(chkDataExtAttr);

        if (ComValidator1.DoValidator())
        {
            if (string.IsNullOrEmpty(txtOrderNo.Text) == false)
            {
                paramBean.OrderNo = int.Parse(txtOrderNo.Text);
            }
            
            dao.InsertUpdate(paramBean);

            ((Design_MasterPage)this.Master).InfoMessage =
                HttpContext.GetGlobalResourceObject(Constants.GLOBAL_RESOURCE_NAME, "I0001").ToString();
        }
        else
        {
            ((Design_MasterPage)this.Master).InfoMessage = ComValidator1.ErrorMessage;
        }
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        CommonDictionaryBean paramBean = new CommonDictionaryBean();
        paramBean.DictNo = txtDictNo.Text;
        paramBean.Catalog = txtCatalog.Text;
        CommonDictionaryDao dao = new CommonDictionaryDao();
        dao.Delete(paramBean);

        // 回传接收的参数
        Context.Items["InpDictNo"] = ViewState["InpDictNo"];
        Context.Items["InpCatalog"] = ViewState["InpCatalog"];
        Context.Items["InpTitle"] = ViewState["InpTitle"];
        Context.Items["InpContent"] = ViewState["InpContent"];

        Context.Items["ParamDictNo"] = ViewState["ParamDictNo"];
        Context.Items["ParamCatalog"] = ViewState["ParamCatalog"];
        Context.Items["ParamTitle"] = ViewState["ParamTitle"];
        Context.Items["ParamContent"] = ViewState["ParamContent"];
        Context.Items["ParamCommand"] = ViewState["ParamCommand"];
        Context.Items["ParamPageIndex"] = ViewState["ParamPageIndex"];

        // 页面跳转到检索页面
        // Server.Transfer("~/App/Master/CommonDictionarySrhForm.aspx", true);
        ControllerUtils.Transfer(this.Context, "~/App/Master/CommonDictionarySrhForm.aspx", true);
    }
}
